using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Linq;

using Soussous.DAO;
using Soussous.DAO.Connection;
using Soussous.Business;

namespace Soussous.DAO
{
    abstract class AbstractDAO<T> where T : Identifiable
    {
        public Table<T> getAll()
        {
            DataContext context = this.getContext();
            Table<T> results = context.GetTable<T>();
            return results;
        }
        public void insert(T theObject) 
        {
            Table<T> results = this.getAll();
            results.InsertOnSubmit(theObject);
            results.Context.SubmitChanges();
        }

        private DataContext getContext()
        {
            AbstractConnection connection = ConnectionFactory.getConnection();
            return connection.open();
        }
    }
}